﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DatabasesClear : System.Web.UI.Page
{
    private ProxyWrapper.UserProxy.UserDetails _objUser = null;
    private string DatabaseId = "0";
    private int _dataCount = 0;
    private bool isCaseSensitive = false;
    private string _dbName = "";
    public int DBId
    {
        get
        {
            return Convert.ToInt32(DatabaseId);
        }

    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            int _dbId = 0;
            if (Session["userObject"] == null)
            {
                Response.Redirect("Default.aspx", false);
            }
            else
            {
                DatabaseId = Request.QueryString["dbid"] != null ? Request.QueryString["dbid"].ToString() : "0";
                _objUser = ((ProxyWrapper.UserProxy.UserDetails)Session["UserObject"]);
                if (Request.QueryString != null && Request.QueryString["msg"] != null)
                {
                    // showMessages.Visible = true;
                    //mmsg.InnerText = Request.QueryString["msg"].ToString();
                }
                if (Int32.TryParse(DatabaseId, out _dbId) && _dbId > 0)
                {
                    LoadSearchData(Request.QueryString["search"] != null ? Request.QueryString["search"].ToString() : "");
                }
            }
        }
        catch (Exception ex)
        {

        }
    }
    private void LoadSearchData(string searchQuery)
    {

        ProxyWrapper.DatabaseServiceWrapper _dbService = new ProxyWrapper.DatabaseServiceWrapper();
        ProxyWrapper.CommonProxyService.DatabaseDetails _dbDetails = _dbService.GetDBDetail(Convert.ToInt32(DatabaseId), _objUser.UserId);
        isCaseSensitive = _dbDetails.IsCaseSensitiveValidation;
        _dataCount = _dbDetails.RowCount;
        _dbName = _dbDetails.DBName;
        //  lstScanData.DataSource = _dbDetails.ScanDataList;
        //  lstScanData.DataBind();
    }
    public string GetUserId()
    {
        return _objUser != null ? _objUser.UserId.ToString() : "0";
    }
    public string GetDatabaseName()
    {
        return _dbName;
    }
    public string GetDatabaseId()
    {
        return Request.QueryString["dbid"] != null ? Request.QueryString["dbid"].ToString() : "0";
    }
    public string GetCaseSensitiveCount()
    {
        if (isCaseSensitive)
            return _dataCount.ToString() + " Case-Sensitive Values";
        else
            return _dataCount.ToString() + " Values";
    }
    protected void btnExport_Click(object sender, EventArgs e)
    {
        try
        {
            ProxyWrapper.DatabaseServiceWrapper _wrapper = new ProxyWrapper.DatabaseServiceWrapper();
            _wrapper.EmptyDB(_objUser.ClientId, DBId, _objUser.HashCode);
            Response.Redirect("Databases.aspx?msg=Database has been successfully emptied.", false);
        }
        catch (Exception)
        {
        }
    }
}